home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Container / Sources / Tracker.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  9.3 KB  |  322 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Tracker.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Container.hpp"
  11.  
  12. #ifndef TRACKER_H
  13. #include "Tracker.h"
  14. #endif
  15.  
  16. #ifndef PROXY_H
  17. #include "Proxy.h"
  18. #endif
  19.  
  20. #ifndef FRAME_H
  21. #include "Frame.h"
  22. #endif
  23.  
  24. // ----- Part Layer -----
  25.  
  26. #ifndef FWCONTXT_H
  27. #include "FWContxt.h"
  28. #endif
  29.  
  30. #ifndef FWUTIL_H
  31. #include "FWUtil.h"
  32. #endif
  33.  
  34. #ifndef FWVIEW_H
  35. #include "FWView.h"
  36. #endif
  37.  
  38. #ifndef FWSCROLR_H
  39. #include "FWScrolr.h"
  40. #endif
  41.  
  42. // ----- OS Layer -----
  43.  
  44. #ifndef FWRECSHP_H
  45. #include "FWRecShp.h"
  46. #endif
  47.  
  48. //========================================================================================
  49. // Runtime Information
  50. //========================================================================================
  51.  
  52. #ifdef FW_BUILD_MAC
  53. #pragma segment odfcontainer
  54. #endif
  55.  
  56. //========================================================================================
  57. //    class CTrackRect
  58. //========================================================================================
  59.  
  60. //----------------------------------------------------------------------------------------
  61. //    CTrackRect constructor
  62. //----------------------------------------------------------------------------------------
  63. CTrackRect::CTrackRect(const FW_CInk& frameInk, const FW_CStyle& frameStyle) :
  64.     fFrameStyle(frameStyle),
  65.     fFrameInk(frameInk)
  66. {
  67. }
  68.  
  69. //----------------------------------------------------------------------------------------
  70. //    CTrackRect destructor
  71. //----------------------------------------------------------------------------------------
  72. CTrackRect::~CTrackRect()
  73. {
  74. }
  75.  
  76. //----------------------------------------------------------------------------------------
  77. //    CTrackRect::GetRectBounds
  78. //----------------------------------------------------------------------------------------
  79. void CTrackRect::GetRectBounds(FW_CRect& bounds) const
  80. {
  81.     bounds = fRect;
  82. }
  83.  
  84. //----------------------------------------------------------------------------------------
  85. //    CTrackRect::SetRectGeometry
  86. //----------------------------------------------------------------------------------------
  87. void CTrackRect::SetRectGeometry(const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint)
  88. {
  89.     if (anchorPoint.x < currentPoint.x)
  90.     {
  91.         fRect.left = anchorPoint.x;
  92.         fRect.right = currentPoint.x;
  93.     }
  94.     else
  95.     {
  96.         fRect.left = currentPoint.x;
  97.         fRect.right = anchorPoint.x;
  98.     }
  99.     
  100.     if (anchorPoint.y < currentPoint.y)
  101.     {
  102.         fRect.top = anchorPoint.y;
  103.         fRect.bottom = currentPoint.y;
  104.     }
  105.     else
  106.     {
  107.         fRect.top = currentPoint.y;
  108.         fRect.bottom = anchorPoint.y;
  109.     }
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. //    CTrackRect::TrackFeedback
  114. //----------------------------------------------------------------------------------------
  115. void CTrackRect::TrackFeedback(Environment* ev,
  116.                                 ODFacet* facet,
  117.                                 FW_CGraphicContext& gc,
  118.                                 const FW_CPoint& anchorPoint, 
  119.                                 const FW_CPoint& currentPoint, 
  120.                                 FW_Boolean erase)
  121. {
  122. FW_UNUSED(ev);
  123. FW_UNUSED(facet);
  124.     if (!erase)
  125.         SetRectGeometry(anchorPoint, currentPoint);
  126.  
  127.     FW_CRect rect(fRect);
  128.     FW_Fixed pensize = fFrameStyle.GetPenSize();
  129.     FW_Fixed half = FW_Half(pensize);
  130.     rect.Inset(-half, -half);
  131.  
  132.     FW_CRectShape::RenderRect(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
  133. }
  134.  
  135. //========================================================================================
  136. //    class CResizeTracker
  137. //========================================================================================
  138.  
  139. //----------------------------------------------------------------------------------------
  140. //    CResizeTracker::CResizeTracker
  141. //----------------------------------------------------------------------------------------
  142.  
  143. CResizeTracker::CResizeTracker(Environment* ev,
  144.                                 FW_CView* view, ODFacet* facet, 
  145.                                 CProxy* theProxy, short whichHandle,
  146.                                 const FW_CInk& resizeInk, const FW_CStyle& resizeStyle) 
  147. :    FW_CTracker(ev, view, facet),
  148.     fProxy(theProxy),
  149.     fWhichHandle(whichHandle),
  150.     fResizeInk(resizeInk),
  151.     fResizeStyle(resizeStyle),
  152.     fErase(FALSE),
  153.     fScroller(view->GetFrame(ev)->GetScroller(ev))
  154. {
  155. }
  156.  
  157. //----------------------------------------------------------------------------------------
  158. //    CResizeTracker::~CResizeTracker
  159. //----------------------------------------------------------------------------------------
  160.  
  161. CResizeTracker::~CResizeTracker()
  162. {
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. //    CResizeTracker::BeginTracking
  167. //----------------------------------------------------------------------------------------
  168.  
  169. FW_CPoint CResizeTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
  170. {
  171.     FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  172.     
  173.     FW_Fixed handleSize = CalcHandlePenSize(((CContainerFrame*)GetView(ev)->GetFrame(ev))->GetZoomFactor());
  174.     
  175.     FW_CRectShape handle(FW_kZeroRect, FW_kFill);
  176.     handle.SetInk(FW_kInvertInk);
  177.     fProxy->CalcHandle(fWhichHandle, &handle, handleSize);
  178.     handle.Render(vc);    // redraw the handle
  179.  
  180.     FW_CPoint handleCenter;
  181.     fProxy->GetHandleCenter(fWhichHandle, handleCenter);
  182.     fDelta = anchorPoint - handleCenter;
  183.  
  184.     fScroller->InitializeAutoScroll(ev);
  185.     
  186.     return handleCenter;
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. //    CResizeTracker::ContinueTracking
  191. //----------------------------------------------------------------------------------------
  192.  
  193. FW_CPoint CResizeTracker::ContinueTracking(Environment* ev,
  194.                                             const FW_CPoint& anchorPoint, 
  195.                                             const FW_CPoint& previousPoint, 
  196.                                             const FW_CPoint& currentPoint)
  197. {
  198. FW_UNUSED(anchorPoint);
  199.  
  200.     // ----- Adjust for the size of the handle
  201.     FW_CPoint curLoc(currentPoint - fDelta);        
  202.  
  203.     if (previousPoint != curLoc)
  204.     {
  205.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  206.     
  207.         if (fErase)
  208.             fProxy->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, previousPoint);    // erase
  209.         else
  210.             fProxy->RenderSelectionFrame(vc);
  211.                 
  212.         fScroller->AutoScroll(ev, currentPoint, &vc);
  213.  
  214.         fProxy->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, curLoc);    // draw
  215.         
  216.         fErase = TRUE;                
  217.     }
  218.     
  219.     return curLoc;
  220. }
  221.  
  222. //----------------------------------------------------------------------------------------
  223. //    CResizeTracker::EndTracking
  224. //----------------------------------------------------------------------------------------
  225.  
  226. FW_Boolean CResizeTracker::EndTracking(Environment* ev,
  227.                                     const FW_CPoint& anchorPoint, 
  228.                                     const FW_CPoint& lastPoint)
  229. {
  230.     fLastLocation = lastPoint - fDelta;
  231.     
  232.     if (fErase)
  233.     {
  234.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  235.     
  236.         fProxy->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, fLastLocation);
  237.     }
  238.     
  239.     return anchorPoint != lastPoint;
  240. }
  241.  
  242. //========================================================================================
  243. //    class CSelectTracker
  244. //========================================================================================
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    CSelectTracker constructor
  248. //----------------------------------------------------------------------------------------
  249.  
  250. CSelectTracker::CSelectTracker(Environment* ev, FW_CView* view, ODFacet* facet, CTrackRect* theShape) :
  251.     FW_CTracker(ev, view, facet),
  252.     fShape(theShape),
  253.     fErase(FALSE),
  254.     fScroller(view->GetFrame(ev)->GetScroller(ev))
  255. {
  256. }
  257.  
  258. //----------------------------------------------------------------------------------------
  259. //    CSelectTracker destructor
  260. //----------------------------------------------------------------------------------------
  261.  
  262. CSelectTracker::~CSelectTracker()
  263. {
  264. }
  265.  
  266. //----------------------------------------------------------------------------------------
  267. //    CSelectTracker::BeginTracking
  268. //----------------------------------------------------------------------------------------
  269.  
  270. FW_CPoint CSelectTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
  271. {
  272.     fScroller->InitializeAutoScroll(ev);
  273.     return anchorPoint;
  274. }
  275.  
  276. //----------------------------------------------------------------------------------------
  277. //    CSelectTracker::ContinueTracking
  278. //----------------------------------------------------------------------------------------
  279.  
  280. FW_CPoint CSelectTracker::ContinueTracking(Environment* ev,
  281.                                         const FW_CPoint& anchorPoint, 
  282.                                         const FW_CPoint& previousPoint, 
  283.                                         const FW_CPoint& currentPoint)
  284. {
  285.     FW_CPoint curLoc(currentPoint);
  286.     
  287.     if (previousPoint != curLoc)
  288.     {
  289.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  290.         
  291.         if (fErase)
  292.             fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, previousPoint, TRUE);
  293.         
  294.         fScroller->AutoScroll(ev, currentPoint, &vc);
  295.  
  296.         fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, curLoc, FALSE);
  297.         
  298.         fErase = TRUE;
  299.     }
  300.     
  301.     return curLoc;
  302. }
  303.  
  304. //----------------------------------------------------------------------------------------
  305. //    CSelectTracker::EndTracking
  306. //----------------------------------------------------------------------------------------
  307.  
  308. FW_Boolean CSelectTracker::EndTracking(Environment* ev,
  309.                                     const FW_CPoint& anchorPoint, 
  310.                                     const FW_CPoint& lastPoint)
  311. {
  312.     if (fErase)
  313.     {
  314.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  315.         
  316.         fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, lastPoint, TRUE);
  317.     }
  318.     
  319.     return anchorPoint != lastPoint;
  320. }
  321.  
  322.